﻿using System.Management.Automation;
using Microsoft.SharePoint.Client;


namespace SharePointOnlineCmdlets
{
    /// <summary>
    /// Publishes a content type in the content type hub
    /// </summary>
    [Cmdlet(VerbsData.Publish, "SPOContentType")]
    public class PublishSPOContentType : Cmdlet
    {
        [Parameter(Mandatory = true, ValueFromPipeline = true)]
        public Site Site { get; set; }

        [Parameter(Mandatory = true)]
        public string ContentTypeId { get; set; }

        [Parameter]
        public SwitchParameter Republish { get; set; }

        protected override void ProcessRecord()
        {
            var action = Republish.IsPresent ? "republish" : "publish";
            SPHelpers.CallContentTypePublishing(Site.Context as ClientContext,ContentTypeId, action); 
            WriteObject(Site);
        }
    }

    /// <summary>
    /// Unpublishes a content type in the content type hub
    /// </summary>
    [Cmdlet(VerbsData.Unpublish, "SPOContentType")]
    public class UnpublishSPOContentType : Cmdlet
    {
        [Parameter(Mandatory = true, ValueFromPipeline = true)]
        public Site Site { get; set; }

        [Parameter(Mandatory = true)]
        public string ContentTypeId { get; set; }

        protected override void ProcessRecord()
        {
            SPHelpers.CallContentTypePublishing(Site.Context as ClientContext, ContentTypeId, "unpublish");
            WriteObject(Site);
        }
    }

}
